//
//  HOTUtils.m
//  Genpara
//
//  Created by AndyChang.zhang on 14-9-22.
//  Copyright (c) 2014年 zhangchh. All rights reserved.
//

#import "HOTUtils.h"
#import "ZZZPullDownModel.h"

@interface HOTUtils() {
    
    
}

@end

@implementation HOTUtils

+(NSArray *)getPullModelListFromPlist {
    
//    NSMutableArray *modelList = [[NSMutableArray alloc] initWithCapacity:10];
//    
//    NSMutableArray *regionlList = [[NSMutableArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"RegionList" ofType:@"plist"]] init];
//    for (int i =0; i < regionlList.count; i ++) {
//        
//        NSDictionary *dic = [regionlList objectAtIndex:i];
//        
//        ZZZPullDownModel *model = [[ZZZPullDownModel alloc] init];
//        model.titleStr = [dic objectForKey:@"name"];
//        model.value = [dic objectForKey:@"id"];
//        
//        [modelList addObject:model];
//    }
    
    return [self getRegionModelList];
}

+(NSArray *)getJobPullModelListFromPlist {
    
    NSMutableArray *modelList = [[NSMutableArray alloc] initWithCapacity:10];
    
    NSMutableArray *jobTypeList = [[NSMutableArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"jobType" ofType:@"plist"]] init];
    for (int i =0; i < jobTypeList.count; i ++) {
        
        NSDictionary *dic = [jobTypeList objectAtIndex:i];
        
        ZZZPullDownModel *model = [[ZZZPullDownModel alloc] init];
        model.titleStr = [dic objectForKey:@"jname"];
        model.value = [dic objectForKey:@"jid"];
        
        [modelList addObject:model];
    }
    
    return modelList;
}

+(NSArray *)getRegionModelList {
    
    NSMutableArray *modelList = [[NSMutableArray alloc] initWithCapacity:10];
    
    NSMutableArray *regionlList = [HOTConfig config].regionlList;
    for (int i =0; i < regionlList.count; i ++) {
        
        NSDictionary *dic = [regionlList objectAtIndex:i];
        
        ZZZPullDownModel *model = [[ZZZPullDownModel alloc] init];
        model.titleStr = [dic objectForKey:@"name"];
        model.value = [dic objectForKey:@"id"];
        
        NSArray *subList = [dic objectForKey:@"list"];
        
        NSMutableArray *subModelArr = [NSMutableArray array];
        
        for (NSString *subStr in subList) {
            
            ZZZPullDownModel *submodel = [[ZZZPullDownModel alloc] init];
            submodel.titleStr = subStr;
            submodel.value = subStr;
            
            [subModelArr addObject:submodel];
        }
        
        NSDictionary *newDic = @{@"list":subModelArr};
        model.userInfo = newDic;
        [modelList addObject:model];
    }
    
    return modelList;
}

/**
 *  获取保有资格
 *
 *  @return return value description
 */
+(NSArray *)getCapcityPullModelListFromPlist {
    
    NSMutableArray *modelList = [[NSMutableArray alloc] initWithCapacity:10];
    
    NSMutableArray *certificationList = [[NSMutableArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"certification" ofType:@"plist"]] init];
    for (int i =0; i < certificationList.count; i ++) {
        
        NSDictionary *dic = [certificationList objectAtIndex:i];
        
        ZZZPullDownModel *model = [[ZZZPullDownModel alloc] init];
        model.titleStr = [dic objectForKey:@"cname"];
        model.value = [dic objectForKey:@"cid"];
        
        [modelList addObject:model];
    }
    
    return modelList;
}

/**
 *  获取健康诊断
 *
 *  @return return value description
 */
+(NSArray *)getHealthPullModelListFromPlist {
    
    NSMutableArray *modelList = [[NSMutableArray alloc] initWithCapacity:10];
    
    NSMutableArray *healthList = [[NSMutableArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"health" ofType:@"plist"]] init];
    for (int i =0; i < healthList.count; i ++) {
        
        NSDictionary *dic = [healthList objectAtIndex:i];
        
        ZZZPullDownModel *model = [[ZZZPullDownModel alloc] init];
        model.titleStr = [dic objectForKey:@"hname"];
        model.value = [dic objectForKey:@"hid"];
        
        [modelList addObject:model];
    }
    
    return modelList;
}

/**
 *  分类id
 *
 *  @param cId 分类id
 *
 *  @return name
 */
+(NSString *)getNotesCateNameWithId:(NSString *)cId {
    
    NSString *cName = @"";

    NSMutableArray *catelList = [[NSMutableArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"notes_cate" ofType:@"plist"]] init];
    for (int i =0; i < catelList.count; i ++) {
        
        NSDictionary *dic = [catelList objectAtIndex:i];
        
        if ([[dic objectForKey:@"id"] isEqualToString:cId]) {
            
            cName = [dic objectForKey:@"name"];
            break;
        }
    }
    
    return cName;
}

+(BOOL)isNullOrEmpty:(NSString *)str{
    
    if (str == nil || str.length == 0) {
        
        return YES;
    }
    return NO;
}

+(BOOL)isNotNullOrEmpty:(NSString *)str {
    
    return ![HOTUtils isNullOrEmpty:str];
}

+(NSString *)getString:(NSString *)str {
    
    if ([HOTUtils isNullOrEmpty:str]) {
        
        return @"";
    }
    
    return str;
}

+(NSString *)getString:(NSString *)str defaultStr:(NSString *)defStr {
    
    if ([HOTUtils isNullOrEmpty:str]) {
        
        return defStr;
    }
    
    return str;
}

+(UIToolbar *) createInputAccessoryViewWithName:(NSString *)btnName target:(id)target action:(SEL)selector {
    
    //取消按钮
    UIToolbar * toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, ZZZ_SCREEN_WIDTH, 44)];
    [toolBar setBarStyle: UIBarStyleBlackTranslucent];
    
    //完成按钮
    UIButton *doneBtn = [[UIButton alloc] initWithFrame:CGRectMake(ZZZ_SCREEN_WIDTH - 5 -80, 10, 80, 22)];
    [doneBtn setTitle:btnName forState:UIControlStateNormal];
    doneBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
    doneBtn.titleLabel.font = [UIFont boldSystemFontOfSize:18];
    [doneBtn addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    [doneBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [doneBtn setTitleColor:[UIColor colorWithWhite:0.600 alpha:1.000] forState:UIControlStateHighlighted];
    
    [toolBar addSubview:doneBtn];
    
    return toolBar;
}

@end
